refactor(renderer): refactor renderer in multiple files#338
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the UI renderer into smaller modules (events/buffer/context) and updates RenderState’s indexing strategy, with corresponding test updates to use the new structure.
Changes:
- Split renderer responsibilities into
renderer.events,renderer.buffer, and a shared singletonrenderer.ctx. - Replace RenderState’s per-line index with sorted range arrays and add a cached max-line optimization.
- Add batch update support in
output_windowto reduce repeatedmodifiabletoggling during multi-step buffer updates.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/render_state_spec.lua | Updates assertions for new range-based validity flags and adds coverage for early-return paths. |
| tests/unit/permission_integration_spec.lua | Switches from renderer internals to renderer.events + renderer.ctx for integration-style behavior. |
| tests/unit/hooks_spec.lua | Routes hook tests through renderer.events handlers. |
| tests/unit/cursor_tracking_spec.lua | Updates scrolling tests to use ctx.prev_line_count and message update events. |
| tests/manual/renderer_replay.lua | Reads actions from renderer.ctx.render_state instead of renderer internals. |
| tests/helpers.lua | Captures actions via renderer.ctx.render_state. |
| lua/opencode/ui/renderer/events.lua | New module containing renderer event handlers (message/part/session/permission/question/etc.). |
| lua/opencode/ui/renderer/ctx.lua | New shared mutable renderer context (singleton via require cache). |
| lua/opencode/ui/renderer/buffer.lua | New module encapsulating buffer writes, diff-optimized part replacement, and rerender helpers. |
| lua/opencode/ui/renderer.lua | Becomes orchestrator: subscriptions, reset/teardown, full-session render, scrolling, and public accessors. |
| lua/opencode/ui/render_state.lua | Replaces line index maps with sorted ranges + binary search; adds snapshot-id index + max-line caching. |
| lua/opencode/ui/question_window.lua | Calls question rendering/clearing via renderer.events. |
| lua/opencode/ui/permission_window.lua | Calls permissions rendering via renderer.events. |
| lua/opencode/ui/output_window.lua | Adds begin_update/end_update batching and updates buffer validity checks. |
| lua/opencode/ui/debug_helper.lua | Uses renderer.ctx.render_state for message lookup. |
| lua/opencode/state.lua | Removes legacy wrapper module file (module now resolves via opencode/state/init.lua). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.